<?php
include($folder.'/layouts/code-behind/backend.php');
function blc_unnepek_select($from, $itemsPerPage, $sortColumn, $sortDirection)
{
	$orderBy = $sortColumn.'_'.$sortDirection;

	return query('
		SELECT 
			f.id AS id, 
			m.name AS month_name, 
			f.dayofmonth AS dayofmonth, 
			f.name AS name, 
			f.month_id AS month_id
		FROM feast f
			INNER JOIN month m 
				ON m.id = f.month_id
		ORDER BY
			CASE WHEN :orderBy = \'month_id_asc\' THEN f.month_id END ASC,
			CASE WHEN :orderBy = \'month_id_asc\' THEN f.dayofmonth END ASC,
			CASE WHEN :orderBy = \'month_id_desc\' THEN f.month_id END DESC,
			CASE WHEN :orderBy = \'month_id_desc\' THEN f.dayofmonth END DESC,
			CASE WHEN :orderBy = \'name_asc\' THEN f.name END ASC,
			CASE WHEN :orderBy = \'name_desc\' THEN f.name END DESC
		LIMIT :from,:itemsPerPage', 
		array('from'=>$from, 'itemsPerPage'=>$itemsPerPage, 'orderBy'=>$orderBy));
}
function blc_unnepek_select_count()
{
	return queryScalar('SELECT COUNT(*) FROM feast', null);
}
?>